home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-06-10 | 22.6 KB | 879 lines | [TEXT/MPS ] |
- {------------------------------------------------------------------------------
- #
- # Momentum CDEV
- #
- # MoCDEV.p - Pascal Source
- #
- # Versions:
- #
- # Components: MOCDEV.p
- # MoCDEV.make
- # MoCDEV.r
- # MoCDEV.rsrc
- #
- ------------------------------------------------------------------------------}
-
-
- UNIT MoCDEVUnit;
-
- INTERFACE
-
- USES
- Traps, GestaltEqu, MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf, SANE;
-
- CONST
- kGetPtrGestaltSelector = 'gPtr';
- kGestaltCodeRsrcType = 'gCOD';
- kGestaltCodeRsrcID = 128;
-
- MOSignature = 'moMO'; { init signature }
- kPrefResType = 'MOdt';
- kPrefResNum = -4040;
-
- { PreferenceFileName = 'Momentum Prefs';
- cdevSignature = MOSignature;
- PrefSignature = 'pref'; }
-
- kWantMoCkBox = 1;
- kOnlyFinderCkBox = 2;
- kMoCreditsButton = 3;
- kMoFolkloreButton = 4;
- kGravForceEText = 5;
- kGravClockEText = 6;
- kDeskFricEText = 7;
- kBounceFricEText = 8;
- kIconUserItem = 9;
- kCreditTextUserItem = 10;
- kMoHelpButton = 11;
- kWantSoundCkBox = 12;
-
- BaseCdevResID = -4040;
-
- kDefaultDeskFrictn = 10;
- kDefaultBouncFrictn = 10;
- kDefaultGravForce = 10;
- kDefaultClockSetting = 6;
-
- kDefaultAnimationSpeed = 6;
-
- kBroughtToYouByResID = -4043;
- kOfficialNicknameResID = -4044;
-
- kMoFolkloreDlogID = -4045;
- kMoCreditsDlogID = -4046;
- kMoHelpDlogID = -4047;
-
-
- TYPE
- TossParameters = record
- DeskFrictn : integer;
- BouncFrictn : integer;
- GravForce : integer;
- ClockDirection : integer;
- GravVector : point;
- MoIsRunning : boolean;
- OnlyInFinder : boolean;
- MakeSound : integer; { if zero, don’t do sounds! }
- SndResNum : integer;
- { from here on down, are the INIT globals...
- SndChannel : SndChannelPtr;
- TossVelocityV : longint;
- TossVelocityH : longint;
- RegionLoc : point;
- ElapsedTicks : longint;
- LongPosition : LongPt;
- NoMoveCycles : integer; }
- end;
-
- TossParamPtr = ^TossParameters;
-
- { Units for the param blk:
- DeskFrictn - 1-100
- BouncFrictn - 1-100
- GravForce - 0-100
- GravDirectn - vector containing gravity direction w/out magnitude
- GravVector - pixels/tick (point w/ hor & ver components) to sum with the current velocity. }
-
-
- CDEVDataRec = record
- MoInfo : TossParameters;
- lastIconRes : integer;
- IconFlipSpeed : integer;
- lastDrawTick : longint;
- XtraTextResID : integer;
- XtraTextLeft : integer;
- end;
- CDEVDataPtr = ^CDEVDataRec;
- CDEVDataHdl = ^CDEVDataPtr;
-
-
-
- FUNCTION CDEVENTRY (message, item, numItems, CPanelID: INTEGER;
- VAR theEvent: EventRecord;
- cdevStorage : Handle;
- CPDialog : DialogPtr) : Handle;
-
- IMPLEMENTATION
-
-
- PROCEDURE DrawResPICT (picResNum: integer; pictop, picleft: integer); FORWARD;
- PROCEDURE DrawFinderOnlyCheckBox (ckON: boolean); FORWARD;
- PROCEDURE SetCheckBox (theDialog: DialogPtr; ItemNo: integer; Setting: boolean); FORWARD;
- FUNCTION GetCheckBox (theDialog: DialogPtr; ItemNo: integer): boolean; FORWARD;
- PROCEDURE FlipCheckBox (theDialog: DialogPtr; chkItem: integer); FORWARD;
- PROCEDURE GetItemBounds (theDialog: DialogPtr; ItemNo: integer; var ItemBox: rect); FORWARD;
- PROCEDURE SetDItemText (theDialog: DialogPtr; ItemNo: integer; theText: Str255); FORWARD;
- FUNCTION GetDItemNum (theDialog: DialogPtr; ItemNo: Integer): integer; FORWARD;
- PROCEDURE SetDItemNum (theDialog: DialogPtr; ItemNo, value: Integer); FORWARD;
- PROCEDURE GetDItemText (theDialog: DialogPtr; ItemNo: Integer; VAR txt: str255); FORWARD;
- PROCEDURE ItemActivate (theDialog: DialogPtr; ItemNo: integer; turnON: boolean); FORWARD;
- FUNCTION ReadCDEVResource (rsrcType: resType; rsrcNum: integer; var dataHdl: univ handle): boolean; FORWARD;
- FUNCTION WriteCDEVResource (rsrcType: resType; rsrcNum: integer; dataPtr: univ Ptr; dataSize: longint): boolean; FORWARD;
- PROCEDURE ReadInMoPrefs (ConfigData: CDEVDataHdl); FORWARD;
- PROCEDURE ValidateMoData (valiData: CDEVDataHdl); FORWARD;
- PROCEDURE GetCurrentMoData (valiData: CDEVDataHdl; CPDialog: DialogPtr; numItems: integer); FORWARD;
- PROCEDURE FillDlogWithMoData (valiData: CDEVDataHdl; CPDialog: DialogPtr; numItems: integer); FORWARD;
-
- PROCEDURE MoDialogs (dlogID: integer); FORWARD;
- PROCEDURE BounceAlongWithMO (cdevData: CDEVDataHdl; CPDialog: DialogPtr); FORWARD;
-
- FUNCTION GetGestaltPtrReference (VAR DataPtr: ptr): OSErr; FORWARD;
-
-
-
- FUNCTION CDEVENTRY (message, item : INTEGER;
- numItems, CPanelID : INTEGER;
- VAR theEvent : EventRecord;
- cdevStorage : Handle;
- CPDialog : DialogPtr) : Handle;
- { This is the main dispatcher. It must be the first code in the cdev.
- CDEVENTRY's dispatcher responds only to the following messages from the Control Panel:
- macDev - To indicate what machines it is available on.
- initDev - To set up some temporary storage and get the caret started.
- hitDev, closeDev, updateDev, activDev, deActivDev }
-
- VAR
- rtnTRUE : boolean;
- IsChecked : boolean;
- tempChar : CHAR;
- dataHdl : CDEVDataHdl;
- ourItem : integer;
- ItemBox : rect;
- dataPtr : ptr;
-
- BEGIN
- IF (message = macDev)
- THEN CDEVENTRY := Handle (1) {we work on every machine}
- ELSE IF (cdevStorage <> NIL) THEN BEGIN
- TextFont (geneva);
- CASE (message) OF
- initDev: {initialize cdev}
- begin
- cdevStorage := NewHandle(SIZEOF(CDEVDataRec)); {create private storage}
- if (cdevStorage <> nil) then
- begin
- dataHdl := CDEVDataHdl(cdevStorage);
- ReadInMoPrefs (dataHdl);
- end;
- SelIText(CPDialog, numItems + kGravForceEText, 0, 255);
-
- FillDlogWithMoData (dataHdl, CPDialog, numItems);
- with dataHdl^^ do
- begin
- lastIconRes := -4043;
- IconFlipSpeed := kDefaultAnimationSpeed;
- lastDrawTick := 0;
- IF (ODD(TickCount))
- THEN
- begin
- XtraTextResID := kBroughtToYouByResID;
- XtraTextLeft := 107;
- end
- ELSE
- begin
- XtraTextResID := kOfficialNicknameResID;
- XtraTextLeft := 105;
- end;
- end; { with }
-
- end;
- hitDev:
- begin
- ourItem := item - numItems;
- dataHdl := CDEVDataHdl (cdevStorage);
-
- case (ourItem) of
- kWantMoCkBox:
- begin
- FlipCheckBox(CPDialog, item);
- rtnTRUE := GetCheckBox (CPDialog, item);
- IF (NOT rtnTRUE)
- THEN
- begin
- GetItemBounds (CPDialog, kOnlyFinderCkBox + numItems, ItemBox);
- ItemBox.bottom := ItemBox.bottom + 24;
- ItemBox.right := ItemBox.right + 24;
- EraseRect (ItemBox);
- end;
- ItemActivate (CPDialog, kOnlyFinderCkBox + numItems, rtnTRUE);
- ItemActivate (CPDialog, kWantSoundCkBox + numItems, rtnTRUE);
- DrawFinderOnlyCheckBox (rtnTRUE);
- end;
- kOnlyFinderCkBox:
- FlipCheckBox(CPDialog, item);
- kWantSoundCkBox:
- FlipCheckBox(CPDialog, item);
- kMoCreditsButton:
- MoDialogs (kMoCreditsDlogID);
- kMoFolkloreButton:
- MoDialogs (kMoFolkloreDlogID);
- kMoHelpButton:
- MoDialogs (kMoHelpDlogID);
- kIconUserItem:
- with dataHdl^^ do
- begin
- IF (IconFlipSpeed = kDefaultAnimationSpeed)
- THEN IconFlipSpeed := 0
- ELSE IconFlipSpeed := kDefaultAnimationSpeed;
-
- { << code to install current cdev params when icon is clicked on >> }
- HLock (handle (dataHdl));
- with MoInfo do begin
- GetCurrentMoData (dataHdl, CPDialog, numItems);
- ValidateMoData (dataHdl);
-
- IF (GetGestaltPtrReference (DataPtr) = noErr)
- THEN
- BlockMove (@DeskFrictn, DataPtr, sizeof (TossParameters));
- end;
- HUnlock (handle (dataHdl));
- end;
- kCreditTextUserItem:
- begin
- with dataHdl^^ do
- begin
- IF (XtraTextResID = kBroughtToYouByResID)
- THEN
- begin
- XtraTextResID := kOfficialNicknameResID;
- XtraTextLeft := 105;
- end
- ELSE
- begin
- XtraTextResID := kBroughtToYouByResID;
- XtraTextLeft := 107;
- end;
- end;
- GetItemBounds (CPDialog, kCreditTextUserItem, ItemBox);
- EraseRect (ItemBox);
- DrawResPICT (dataHdl^^.XtraTextResID, 238, dataHdl^^.XtraTextLeft);
- end;
- otherwise
- ;
- end; { case }
- end;
-
- closeDev:
- begin
- dataHdl := CDEVDataHdl (cdevStorage);
- HLock (handle (dataHdl));
- with dataHdl^^, MoInfo do begin
- GetCurrentMoData (dataHdl, CPDialog, numItems);
- ValidateMoData (dataHdl);
-
- IF (GetGestaltPtrReference (DataPtr) = noErr)
- THEN
- BlockMove (@DeskFrictn, DataPtr, sizeof (TossParameters))
- ELSE
- ourItem := Alert (-4041, nil);
-
- rtnTRUE := WriteCDEVResource (kPrefResType, kPrefResNum, @DeskFrictn, sizeof (TossParameters));
- end;
- HUnlock (handle (dataHdl));
- DisposHandle (handle(dataHdl));
- end;
- nulDev:
- BounceAlongWithMO (CDEVDataHdl (cdevStorage), CPDialog);
- updateDev:
- BEGIN
- dataHdl := CDEVDataHdl (cdevStorage);
- DrawResPICT (BaseCdevResID, 11, 105);
- BounceAlongWithMO (dataHdl, CPDialog);
- DrawFinderOnlyCheckBox (GetCheckBox (CPDialog, kWantMoCkBox + numItems));
- DrawResPICT (dataHdl^^.XtraTextResID, 238, dataHdl^^.XtraTextLeft);
- END;
- activDev:
- ;
- deActivDev:
- ;
- cutDev:
- DlgCut (CPDialog);
- copyDev:
- DlgCopy(CPDialog);
- pasteDev:
- DlgPaste (CPDialog);
- clearDev:
- DlgDelete (CPDialog);
- keyEvtDev: { the dialog mgr responds to key downs }
- ;
- otherwise;
- END; { CASE message }
-
- CDEVENTRY := cdevStorage; { if (cdevStorage = NIL) on exit then ControlPanel will put up error }
- END; { cdevStorage <> NIL }
- END; { CDEVENTRY }
-
-
-
- { ========================== Support routines that don't KNOW MO ========================== }
-
- PROCEDURE DrawResPICT (picResNum: integer; pictop, picleft: integer);
- { this proc assumes that the pict resource is a purgeable resource }
- var
- PicRect: rect;
- PictHand: picHandle;
- begin
- PictHand := GetPicture(picResNum);
- PicRect := PictHand^^.picFrame;
- OffsetRect(PicRect, picleft - PicRect.left, pictop - PicRect.top);
- DrawPicture(PictHand, PicRect);
- end;
-
-
- PROCEDURE SetCheckBox (theDialog: DialogPtr; ItemNo: integer; Setting: boolean);
- { purpose: change the settings of checkboxes}
- const
- Chk_On = 1; {check on/off buttons}
- Chk_Off = 0;
- var
- NumSet: Integer;
- ItemTYPE: Integer;
- ItemBox: Rect;
- ItemHdl: Handle;
- begin
- IF (Setting)
- THEN
- NumSet := Chk_On
- ELSE
- NumSet := Chk_Off;
- GetDItem (theDialog, ItemNo, ItemTYPE, ItemHdl, ItemBox);
- SetCtlValue (ControlHandle(ItemHdl), NumSet);
- end;
-
-
- FUNCTION GetCheckBox (theDialog: DialogPtr; ItemNo: integer): boolean;
- var
- NumSet: Integer;
- ItemTYPE: Integer;
- ItemBox: Rect;
- ItemHdl: Handle;
- begin
- GetDItem (theDialog, ItemNo, ItemTYPE, ItemHdl, ItemBox);
- NumSet := GetCtlValue (ControlHandle(ItemHdl));
- GetCheckBox := (NumSet = 1);
- end;
-
-
- PROCEDURE FlipCheckBox (theDialog: DialogPtr; chkItem: integer);
- var
- newSetting : boolean;
- begin
- newSetting := NOT GetCheckBox(theDialog, chkItem);
- SetCheckBox(theDialog, chkItem, newSetting);
- end;
-
-
- PROCEDURE GetItemBounds (theDialog: DialogPtr; ItemNo: integer; VAR ItemBox: rect);
- { purpose set the contents of text box 'ItemNo' to 'theText'}
- var
- ItemTYPE: Integer;
- ItemHdl: Handle;
- begin
- GetDItem(theDialog, ItemNo, ItemTYPE, ItemHdl, ItemBox);
- end;
-
-
- PROCEDURE ItemActivate (theDialog : DialogPtr;
- ItemNo : integer;
- turnON : boolean);
- { Activate, deactivate, hilite buttons }
- CONST
- LiveControl = 0; { Activate, deactivate, hilite buttons }
- DeadControl = 255;
- VAR
- ItemType : Integer;
- ItemBox : Rect;
- ItemHdl : Handle;
- BEGIN
- GetDItem (theDialog, ItemNo, ItemType, ItemHdl, ItemBox);
- IF (turnON)
- THEN HiliteControl (ControlHandle (ItemHdl), LiveControl)
- ELSE HiliteControl (ControlHandle (ItemHdl), DeadControl);
- END;
-
-
- PROCEDURE SetDItemText (theDialog: DialogPtr; ItemNo: integer; theText: Str255);
- { purpose set the contents of text box 'ItemNo' to 'theText'}
- var
- ItemTYPE: Integer;
- ItemBox: Rect;
- ItemHdl: Handle;
- begin
- GetDItem(theDialog, ItemNo, ItemTYPE, ItemHdl, ItemBox);
- SetIText(ItemHdl, theText);
- end;
-
-
- PROCEDURE GetDItemText (theDialog: DialogPtr; ItemNo: Integer; VAR txt: str255);
- { return string from text box }
- VAR
- ItemType : Integer;
- ItemBox : Rect;
- ItemHdl : Handle;
- BEGIN
- GetDItem (theDialog, ItemNo, ItemType, ItemHdl, ItemBox);
- GetIText (ItemHdl, txt);
- END;
-
-
- FUNCTION GetDItemNum (theDialog: DialogPtr; ItemNo: Integer): integer;
- VAR
- rtnlong : longint;
- txt : str255;
- BEGIN
- GetDItemText (theDialog, ItemNo, txt);
- StringToNum (txt, rtnlong);
- GetDItemNum := rtnlong;
- END;
-
-
- PROCEDURE SetDItemNum (theDialog: DialogPtr; ItemNo, value: Integer);
- VAR
- rtnlong : longint;
- txt : str255;
- BEGIN
- rtnlong := value;
- NumToString (rtnlong, txt);
- SetDItemText (theDialog, ItemNo, txt);
- END;
-
-
- {######################################################
- Routines that we need to check for availability of Gestalt
- ######################################################}
-
- FUNCTION NumToolboxTraps: Integer;
- begin
- if NGetTrapAddress(_InitGraf, ToolTrap) = NGetTrapAddress($AA6E, ToolTrap) then
- NumToolboxTraps := $200
- else
- NumToolboxTraps := $400;
- end;
-
-
- FUNCTION GetTrapType (theTrap: Integer): TrapType;
- const
- TrapMask = $0800;
- begin
- if (BAND(theTrap, TrapMask) > 0) then
- GetTrapType := ToolTrap
- else
- GetTrapType := OSTrap;
- end;
-
-
- FUNCTION TrapAvailable (theTrap: Integer): Boolean;
- var
- tType: TrapType;
- begin
- tType := GetTrapType(theTrap);
- if tType = ToolTrap then
- begin
- theTrap := BAND(theTrap, $07FF);
- if (theTrap >= NumToolboxTraps) then
- theTrap := _Unimplemented;
- end;
- TrapAvailable := NGetTrapAddress(theTrap, tType) <> NGetTrapAddress(_Unimplemented, ToolTrap);
- end;
-
-
- FUNCTION GestaltAvailable: boolean;
- CONST
- GestaltTrap = $A1AD;
- BEGIN
- GestaltAvailable := TrapAvailable (GestaltTrap);
- END;
-
-
- { ================================= 'MO' routines ================================= }
-
-
- FUNCTION GetGestaltPtrReference (VAR DataPtr: ptr): OSErr; { return error }
- VAR
- gestaltErr : OSErr;
- memLocation : longint;
- BEGIN
- DataPtr := nil;
- GetGestaltPtrReference := -1;
- IF (GestaltAvailable)
- THEN
- begin
- gestaltErr := Gestalt (kGetPtrGestaltSelector, memLocation);
- GetGestaltPtrReference := gestaltErr;
- IF (gestaltErr = noErr)
- THEN
- DataPtr := ptr (memLocation);
- end;
- END;
-
-
- PROCEDURE MoDialogs (dlogID: integer);
- VAR
- Item : integer;
- FolkloreDPtr : DialogPtr;
- BEGIN
- FolkloreDPtr := GetNewDialog (dlogID, NIL, pointer(-1));
- REPEAT
- ModalDialog (NIL, Item);
- UNTIL (Item = 1);
- DisposDialog (FolkloreDPtr);
- END;
-
-
- PROCEDURE BounceAlongWithMO (cdevData: CDEVDataHdl; CPDialog: DialogPtr);
- CONST
- IconTop = 11;
- IconLeft = 105;
- VAR
- drawDelay : integer;
- IcnHandle : handle;
- IRect : rect;
- nowTicks : longint;
- savePort : grafPtr;
- BEGIN
- nowTicks := TickCount;
- drawDelay := cdevData^^.IconFlipSpeed;
- IF (nowTicks > cdevData^^.lastDrawTick + DrawDelay)
- THEN
- begin
- GetPort (savePort);
- SetPort (grafPtr (CPDialog));
- cdevData^^.lastDrawTick := nowTicks;
- IF (cdevData^^.lastIconRes = -4043)
- THEN cdevData^^.lastIconRes := -4033
- ELSE cdevData^^.lastIconRes := cdevData^^.lastIconRes - 1;
- IcnHandle := GetResource ('ICN#', cdevData^^.lastIconRes);
- IF (IcnHandle <> nil)
- THEN
- begin
- SetRect (IRect, IconLeft, IconTop, IconLeft + 32, IconTop + 32);
- PlotIcon (IRect, IcnHandle);
- end;
- SetPort (savePort);
- end;
- END;
-
-
- PROCEDURE DrawFinderOnlyCheckBox (ckON: boolean);
- BEGIN
- if (ckON)
- THEN DrawResPICT (-4042, 81, 168)
- ELSE DrawResPICT (-4041, 81, 168);
- END;
-
-
- PROCEDURE FillDlogWithMoData (valiData: CDEVDataHdl; CPDialog: DialogPtr; numItems: integer);
- BEGIN
- HLock (handle (valiData));
- with valiData^^, MoInfo do
- begin
- SetCheckBox (CPDialog, kWantMoCkBox + numItems, MoIsRunning);
- SetCheckBox (CPDialog, kOnlyFinderCkBox + numItems, OnlyInFinder);
- SetCheckBox (CPDialog, kWantSoundCkBox + numItems, (MakeSound <> 0));
-
- SetDItemNum (CPDialog, kGravForceEText + numItems, GravForce);
- SetDItemNum (CPDialog, kDeskFricEText + numItems, DeskFrictn);
- SetDItemNum (CPDialog, kBounceFricEText + numItems, BouncFrictn);
- SetDItemNum (CPDialog, kGravClockEText + numItems, ClockDirection);
- end;
- END;
-
-
- PROCEDURE GetCurrentMoData (valiData: CDEVDataHdl; CPDialog: DialogPtr; numItems: integer);
- { 'valiData' already locked }
- VAR
- IsChecked : boolean;
- BEGIN
- with valiData^^, MoInfo do begin
- IsChecked := GetCheckBox (CPDialog, kWantMoCkBox + numItems);
- MoIsRunning := IsChecked;
- IsChecked := GetCheckBox (CPDialog, kOnlyFinderCkBox + numItems);
- OnlyInFinder := IsChecked;
- IsChecked := GetCheckBox (CPDialog, kWantSoundCkBox + numItems);
- IF (IsChecked)
- THEN MakeSound := 1
- ELSE MakeSound := 0;
-
- GravForce := GetDItemNum (CPDialog, kGravForceEText + numItems);
- DeskFrictn := GetDItemNum (CPDialog, kDeskFricEText + numItems);
- BouncFrictn := GetDItemNum (CPDialog, kBounceFricEText + numItems);
- ClockDirection := GetDItemNum (CPDialog, kGravClockEText + numItems);
- end;
- END;
-
-
- PROCEDURE ValidateMoData (valiData: CDEVDataHdl);
- VAR
- BadParameter : boolean;
- IsChecked : boolean;
- MoIndex, clock : integer;
- longNum : longint;
- hReal, vReal, g : real;
- typedText : str255;
- BEGIN
- HLock (handle (valiData));
- with valiData^^, MoInfo do
- begin
- BadParameter := FALSE;
- IF ((DeskFrictn < 1) OR (DeskFrictn > 100))
- THEN
- begin
- BadParameter := TRUE;
- DeskFrictn := kDefaultDeskFrictn;
- end;
-
- IF ((BouncFrictn < 1) OR (BouncFrictn > 100))
- THEN
- begin
- BadParameter := TRUE;
- BouncFrictn := kDefaultBouncFrictn;
- end;
-
- IF ((GravForce < 0) OR (GravForce > 100))
- THEN
- begin
- BadParameter := TRUE;
- GravForce := kDefaultGravForce;
- end;
-
- IF ((ClockDirection < 1) OR (ClockDirection > 12))
- THEN
- begin
- BadParameter := TRUE;
- ClockDirection := kDefaultClockSetting;
- end;
-
- IF (BadParameter) THEN
- MoIndex := Alert (BaseCdevResID, nil);
-
- { set 'GravVector' on the way out }
- hReal := 0;
- vReal := 0;
- g := GravForce;
- GravVector.h := 0;
- GravVector.v := 0;
- case ClockDirection of
- 1:
- begin
- hReal := 0.5 * g;
- vReal := -0.866 * g;
- end;
- 2:
- begin
- hReal := 0.866 * g;
- vReal := -0.5 * g;
- end;
- 3:
- begin
- GravVector.h := GravForce;
- GravVector.v := 0;
- end;
- 4:
- begin
- hReal := 0.866 * g;
- vReal := 0.5 * g;
- end;
- 5:
- begin
- hReal := 0.5 * g;
- vReal := 0.866 * g;
- end;
- 6:
- begin
- GravVector.h := 0;
- GravVector.v := GravForce;
- end;
- 7:
- begin
- hReal := -0.5 * g;
- vReal := 0.866 * g;
- end;
- 8:
- begin
- hReal := -0.866 * g;
- vReal := 0.5 * g;
- end;
- 9:
- begin
- GravVector.h := -GravForce;
- GravVector.v := 0;
- end;
- 10:
- begin
- hReal := -0.866 * g;
- vReal := -0.5 * g;
- end;
- 11:
- begin
- hReal := -0.5 * g;
- vReal := -0.866 * g;
- end;
- 12:
- begin
- GravVector.h := 0;
- GravVector.v := -GravForce;
- end;
- otherwise
- begin
- GravVector.h := 0;
- GravVector.v := GravForce;
- ClockDirection := kDefaultClockSetting;
- end;
- end; { case }
- IF ((hReal <> 0) OR (vReal <> 0))
- THEN
- begin
- GravVector.h := ROUND (hReal);
- GravVector.v := ROUND (vReal);
- end;
-
- end; { with }
- HUnlock (handle (valiData));
- END;
-
-
-
- {====================== P R E F R O U T I N E S =======================}
-
-
- FUNCTION ReadCDEVResource (rsrcType: resType; rsrcNum: integer; var dataHdl: univ handle): boolean;
- { Gets resource 'rsrcType' having ID# 'rsrcNum' from the currently open res file. }
- { In a cdev, the system opens the res fork. FUNCTION returns TRUE if data was read, FALSE if not. }
- VAR
- temphdl : handle;
- BEGIN
- temphdl := Get1Resource (rsrcType, rsrcNum);
- IF ((ResError = noErr) AND (temphdl <> nil))
- THEN
- begin
- dataHdl := temphdl;
- ReadCDEVResource := TRUE;
- end
- ELSE
- begin
- dataHdl := nil;
- ReadCDEVResource := FALSE;
- end;
- END; { ReadCDEVResource }
-
-
-
- FUNCTION WriteCDEVResource (rsrcType: resType; rsrcNum: integer; dataPtr: univ Ptr; dataSize: longint): boolean;
- { Writes resource 'rsrcType' having #'rsrcNum' to the open res fork. }
- { In a cdev the is kept open by the system. }
- { FUNCTION returns TRUE if data was read, FALSE if not. }
- VAR
- hdlFlags : signedByte;
- temphdl : handle;
-
- PROCEDURE ExitOnError (ErrNum: OSErr);
- var
- ignoreErr: OSErr;
- begin
- if (ErrNum <> noErr) then
- begin
- WriteCDEVResource := FALSE;
- Exit (WriteCDEVResource);
- end;
- end;
-
- PROCEDURE WriteResHandle;
- var
- ignoreErr: OSErr;
- begin
- HLock (temphdl);
- BlockMove (dataPtr, temphdl^, dataSize);
- HUnlock (temphdl);
- AddResource (temphdl, rsrcType, rsrcNum, '');
- ExitOnError (ResError);
- WriteResource (temphdl);
- ExitOnError (ResError);
- SetResAttrs (temphdl, resPurgeable);
- WriteCDEVResource := TRUE;
- end;
-
- begin
- temphdl := Get1Resource (rsrcType, rsrcNum);
- if ((ResError = noErr) AND (temphdl <> nil))
- THEN
- begin
- RmveResource (temphdl);
- SetHandleSize (temphdl, dataSize);
- WriteResHandle;
- end
- ELSE
- begin
- temphdl := Newhandle (dataSize);
- IF (temphdl <> nil)
- THEN WriteResHandle
- ELSE WriteCDEVResource := FALSE;
- end;
- end; { WriteCDEVResource }
-
-
-
- PROCEDURE ReadInMoPrefs (ConfigData: CDEVDataHdl);
- VAR
- PrefDataOnDisk : boolean;
- index : integer;
- resSize : longint;
- gravH, gravV : integer;
- DataLocation : ptr;
- SrcLocation : ptr;
- resData : handle;
- BEGIN
- HLock (handle (ConfigData));
- with ConfigData^^, MoInfo do begin
- PrefDataOnDisk := FALSE;
- DataLocation := @DeskFrictn;
- PrefDataOnDisk := ReadCDEVResource (kPrefResType, kPrefResNum, resData);
- IF (PrefDataOnDisk)
- THEN
- begin
- HLock (handle (resData));
- SrcLocation := resData^;
- resSize := GethandleSize (resData);
- IF (resSize > sizeof (TossParameters))
- THEN resSize := sizeof (TossParameters);
- BlockMove (SrcLocation, DataLocation, resSize);
- HUnlock (handle (resData));
- end
- ELSE
- begin
- { init all }
- DeskFrictn := kDefaultDeskFrictn;
- BouncFrictn := kDefaultBouncFrictn;
- GravForce := kDefaultGravForce;
- ClockDirection := kDefaultClockSetting;
- MoIsRunning := TRUE;
- OnlyInFinder := FALSE;
- MakeSound := 1; { if zero, don’t do sounds! }
- SndResNum := -32512;
- end;
- end;
- HUnlock (handle (ConfigData));
- END;
-
-
- END. { MoCDEVUnit }
-